#ifndef __MOTOR_H
#define __MOTOR_H
#include "gd32e23x.h"
#include "systick.h"
//AIN
#define RCU_AIN1 RCU_GPIOB
#define AIN1_periph GPIOB
#define AIN1_pin GPIO_PIN_3

#define RCU_AIN2 RCU_GPIOA
#define AIN2_periph GPIOA
#define AIN2_pin GPIO_PIN_15
//BIN
#define RCU_BIN1 RCU_GPIOB
#define BIN1_periph GPIOB
#define BIN1_pin GPIO_PIN_5

#define RCU_BIN2 RCU_GPIOB
#define BIN2_periph GPIOB
#define BIN2_pin GPIO_PIN_4

//pwm
#define PWM_RCU_GPIO      RCU_GPIOB
#define PWM_RCU_TIMER     RCU_TIMER14
#define PWM_timer_periph  TIMER14
#define PWM_gpio_periph   GPIOB
#define PWM_A_pin         GPIO_PIN_14
#define PWM_B_pin         GPIO_PIN_15
#define PWM_A_channel     TIMER_CH_0
#define PWM_B_channel     TIMER_CH_1



#define AIN1(bit_value) gpio_bit_write(AIN1_periph,AIN1_pin,(FlagStatus) bit_value);
#define AIN2(bit_value) gpio_bit_write(AIN2_periph,AIN2_pin,(FlagStatus) bit_value);
#define BIN1(bit_value) gpio_bit_write(BIN1_periph,BIN1_pin,(FlagStatus) bit_value);
#define BIN2(bit_value) gpio_bit_write(BIN2_periph,BIN2_pin,(FlagStatus) bit_value);



#define A_PWM(pulse) timer_channel_output_pulse_value_config(PWM_timer_periph,PWM_A_channel, (uint32_t) pulse)
#define B_PWM(pulse) timer_channel_output_pulse_value_config(PWM_timer_periph,PWM_B_channel, (uint32_t) pulse)
void Motor_Init(void);
int abs(int p);
void Load(int moto1,int moto2);

void Limit(int *motoA,int *motoB);
void Stop(float *Med_Jiaodu,float *Jiaodu);
#endif